loadInitData();
function loadInitData() {
    var token = localStorage.getItem("token");
    console.log("token:"+token);
    $.ajax({
        type: "get",
        url: "/demo/XQing",
        headers: {'token': token},
        success: function (result) {
            var loginCustomer=result.data;
            console.log("==============")
            console.log(result.data)
            if(loginCustomer!=null){
                $(".head-user").hide();
                var customerId = loginCustomer.customerId;
                var url = "/demo/order?customerId=" + customerId;
                // $(".customerIdDZ").html('<span class="dianzanCUSTID">'+loginCustomerId+'</span>');
                $(".customerIdDZ").text(customerId)
                $(".user-menu").html('<li class="text"><a href='+url+'>个人中心</a></li>\n' +
                    '                 <li class="text" id="return"><button style="border: none">退出登录</button></li>');
                $(".user-info").show();
            }else {
                $(".head-user").show();
                $(".user-info").hide();
            }
            $("#return").click(function (){
                var token = localStorage.removeItem("token");
                window.location.href = "http://localhost:8080/demo/index.jsp";
            })
        }
    })
}


movieFarstFilms();
function movieFarstFilms(){
    $.ajax({
        type: "get",
        url: "../films",
        data: {
            movieStatus: 0,
            movieType: "全部",
            movieArea: "全部",
            movieOpenhours: "全部",
            page: 1

        },
        success: function (result) {
            $(".movie-list").html("");
            var data = result.data.records;
            var re = result.data;
            console.log("data:"+data)
            console.log("re:"+re)
            console.log("data.length:"+data.length)
            for (var i =0;i<data.length;i++){
                console.log(data[i]);
                var movieId = data[i].movieId;
                var movieCname =data[i].movieCname;
                var moviePicture = data[i].moviePicture;
                var movieEle = "<li class=\"poster-item\">\n" +
                    "\n" +
                    "                                <a class=\"wrap\" href=\"MovieDetail?movieId="+movieId+"\" >\n" +
                    "                                    <input type=\"hidden\" value=\" "+movieId+"\">\n" +
                    "                                    <img class=\"img-wrap\" src=\"../"+moviePicture+"\" alt=\"\">\n" +
                    "                                    <div class=\"btn-wrap\" >\n" +
                    "                                        <span >"+movieCname+"</span>\n" +
                    "                                    </div>\n" +
                    "                                </a>\n" +
                    "                            </li>";
                $(".movie-list").append(movieEle);
            }
            {
                $(".page-select .pages").text(re.pages)
                $(".page-select .total").text(re.total)
                $(".page-select .current").text(re.current)
            }
            console.log(re);
        }
    })
}


$(".navbar").click(function(event){
    var element=event.target;//事件作用的目标元素
    console.log(element);
    var navbarArr=$(".navbar>li").children();
    for(let i = 0;i<navbarArr.length;i++){
        navbarArr[i].className="";
    }
    element.className="active"

})
$(".tags-a").click(function(event){
    var type=event.target;
    console.log(type.nodeName);
    var tagsArr=$(".tags-a").children();
    for(let i = 0;i<tagsArr.length;i++){
        tagsArr[i].className="";
    }
    if(type.nodeName==="LI")
        type.className="active";
    if(type.nodeName==="A")
        type.parentElement.className="active";
})
$(".tags-b").click(function(event){
    var area=event.target;
    console.log(area.nodeName);
    var tagsArr=$(".tags-b").children();
    for(let i = 0;i<tagsArr.length;i++){
        tagsArr[i].className="";
    }
    if(area.nodeName==="LI")
        area.className="active";
    if(area.nodeName==="A")
        area.parentElement.className="active";
})
$(".tags-c").click(function(event){
    var element=event.target;
    console.log(element.nodeName);
    var tagsArr=$(".tags-c").children();
    for(let i = 0;i<tagsArr.length;i++){
        tagsArr[i].className="";
    }
    if(element.nodeName==="LI")
        element.className="active";
    if(element.nodeName==="A")
        element.parentElement.className="active";
})
$(".cat-sorter").click(function(event){
    var element1=event.target;//事件作用的目标元素
    if(element1.className == "sort-control sort-radio"){
        var sortArr=$(".cat-sorter").children().children();
        for(let i = 0;i<sortArr.length;i++){
        var a = sortArr[i].children[0].children[0].className="sort-control sort-radio";
        }
        element1.className="sort-control sort-radio sort-radio-checked"
    }
    if(element1.className == "sort-control-label"){
        var sortArr=$(".cat-sorter").children().children();
        for(let i = 0;i<sortArr.length;i++){
           var a = sortArr[i].children[0].children[0].className="sort-control sort-radio";
        }
            element1.previousElementSibling.className="sort-control sort-radio sort-radio-checked"
        }
})



var status=0;
var Type ="全部" ;
var Area="全部";
var Openhours="全部";
var page = $(".current").text()
    //上一页，下一页按钮监听
    $(".upper").click(function () {
        if ($(".current").text()==1){
            layer.msg('已经是第一页了')
            return
        }
        movieFilms(status,Type,Area,Openhours,parseInt(page)-1)

    })
$(".down").click(function () {
    if ($(".current").text()==$(".pages").text()){
        layer.msg('已经是最后一页了')
        return
    }
    movieFilms(status,Type,Area,Openhours,parseInt(page)+1)
})


$(".navbar a").click(function(){
    status = $(this).text().replace(/\s*/g,"")
    if (status =="正在热映"){
        status = 0;
    }else if(status =="即将上映"){
        status = 1;
    }else if (status == "经典影片")
        status = 2;
    movieFilms(status,Type,Area,Openhours,1)
})
$(".tags-a li").click(function(){
    Type = $(this).text().replace(/\s*/g,"")
    movieFilms(status,Type,Area,Openhours,1)
})
$(".tags-b li").click(function(){
     Area = $(this).text().replace(/\s*/g,"")
    movieFilms(status,Type,Area,Openhours,1)
})
$(".tags-c li").click(function(){
     Openhours = $(this).text().replace(/\s*/g,"")
    movieFilms(status,Type,Area,Openhours,1)
})
function movieFilms(movieStatus,movieType,movieArea,movieOpenhours,page){
    console.log(movieStatus)
    console.log(movieType)
    console.log(movieArea)
    console.log(movieOpenhours)
    console.log(page)

    $.ajax({
        type: "get",
        url: "../films",
        data: {
            movieStatus: movieStatus,
            movieType: movieType,
            movieArea: movieArea,
            movieOpenhours: movieOpenhours,
            page: page

        },
        success: function (result) {
            $(".movie-list").html("");
            var data = result.data.records;
            var re = result.data;
            console.log("data:"+data)
            console.log(result.data)
            console.log("data.length:"+data.length)

            for (var i =0;i<data.length;i++){
                console.log(data[i]);
                var movieId = data[i].movieId;
                var movieCname =data[i].movieCname;
                var moviePicture = data[i].moviePicture;
                var movieEle = "<li class=\"poster-item\">\n" +
                    "\n" +
                    "                                <a class=\"wrap\" href=\"XQing.html\">\n" +
                    "                                    <input type=\"hidden\" value=\" "+movieId+"\">\n" +
                    "                                    <img class=\"img-wrap\" src=\"../"+moviePicture+"\" alt=\"\">\n" +
                    "                                    <div class=\"btn-wrap\" >\n" +
                    "                                        <span >"+movieCname+"</span>\n" +
                    "                                    </div>\n" +
                    "                                </a>\n" +
                    "                            </li>";
                $(".movie-list").append(movieEle);
            }
            {
                $(".page-select .pages").text(re.pages)
                $(".page-select .total").text(re.total)
                $(".page-select .current").text(re.current)
            }
            console.log(re);
        }
    })
}

